home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CU Amiga Super CD-ROM 21
/
CU Amiga Magazine's Super CD-ROM 21 (1998)(EMAP Images)(GB)[!][issue 1998-04].iso
/
CUCD
/
Programming
/
Python-1.4
/
Source
/
Amiga
/
Python_netlib
/
linkaddr.c
< prev
next >
Wrap
C/C++ Source or Header
|
1996-11-16
|
2KB
|
90 lines
RCS_ID_C = "$Id: linkaddr.c,v 4.1 1994/09/29 23:09:02 jraja Exp $";
/*
* linkaddr.c - link level address parsing
*
* Copyright © 1994 AmiTCP/IP Group,
* Network Solutions Development Inc.
* All rights reserved.
*
* Copyright © 1991 Regents of the University of California.
*/
#if 0
static char sccsid[] = "@(#)linkaddr.c 5.2 (Berkeley) 2/24/91";
#endif
#include <sys/types.h>
#include <sys/socket.h>
#include <net/if.h>
#include <net/if_dl.h>
#include <string.h>
/* States*/
#define NAMING 0
#define GOTONE 1
#define GOTTWO 2
#define RESET 3
/* Inputs */
#define DIGIT (4*0)
#define END (4*1)
#define DELIM (4*2)
#define LETTER (4*3)
void
link_addr(addr, sdl)
register const char *addr;
register struct sockaddr_dl *sdl;
{
register char *cp = sdl->sdl_data;
char *cplim = sdl->sdl_len + (char *)sdl;
register int byte = 0, state = NAMING, new=0;
bzero((char *)&sdl->sdl_family, sdl->sdl_len - 1);
sdl->sdl_family = AF_LINK;
do {
state &= ~LETTER;
if ((*addr >= '0') && (*addr <= '9')) {
new = *addr - '0';
} else if ((*addr >= 'a') && (*addr <= 'f')) {
new = *addr - 'a' + 10;
} else if ((*addr >= 'A') && (*addr <= 'F')) {
new = *addr - 'A' + 10;
} else if (*addr == 0) {
state |= END;
} else if (state == NAMING &&
(((*addr >= 'A') && (*addr <= 'Z')) ||
((*addr >= 'a') && (*addr <= 'z'))))
state |= LETTER;
else
state |= DELIM;
addr++;
switch (state /* | INPUT */) {
case NAMING | DIGIT:
case NAMING | LETTER:
*cp++ = addr[-1]; continue;
case NAMING | DELIM:
state = RESET; sdl->sdl_nlen = cp - sdl->sdl_data; continue;
case GOTTWO | DIGIT:
*cp++ = byte; /*FALLTHROUGH*/
case RESET | DIGIT:
state = GOTONE; byte = new; continue;
case GOTONE | DIGIT:
state = GOTTWO; byte = new + (byte << 4); continue;
default: /* | DELIM */
state = RESET; *cp++ = byte; byte = 0; continue;
case GOTONE | END:
case GOTTWO | END:
*cp++ = byte; /* FALLTHROUGH */
case RESET | END:
break;
}
break;
} while (cp < cplim);
sdl->sdl_alen = cp - LLADDR(sdl);
new = cp - (char *)sdl;
if (new > sizeof(*sdl))
sdl->sdl_len = new;
return;
}